// pages/order/list/index.js
import {
  request
} from '../../../utils/requestUtils';
Page({
  // 页面的初始数据
  data: {
    refreshTriggered: false,
    total: 0,
    page: {
      pageNum: 1,
      pageSize: 10,
    },
    params: {
      orderStatus:'2',
      keywords: ''
    },
    orderList: []
  },
  onLoad() {
     this.getList()
  },
  onShow() {

  },
  // 触底刷新
  getNext() {
    console.log('触底')
    if (this.data.page.pageNum * this.data.page.pageSize >= this.data.total) {
      return
    } else {
      this.data.page.pageNum++;
    }
    this.getList()
  },
  // 下拉刷新
  onScrollRefresh: function () {
    this.setData({
      'page.pageNum': 1,
       orderList:[]
    })
    this.getList()

  },
  // 查询商品信息
  async getList() {
    const result = await request({
      url: `/bus/group_merchant_statement_head/api/list?pageNum=${this.data.page.pageNum}&pageSize=${this.data.page.pageSize}`,
      method: "POST",
      data: {
        name: this.data.params.keywords,
        params: {
          keywords: this.data.params.keywords,
          orderStatus: this.data.params.orderStatus
        }
      }
    })
    this.setData({
      refreshTriggered: false
    })
    if (result.data.code == 200) {
      var orderList = this.data.orderList.concat(result.data.rows)
      console.log('orderList', orderList)
      this.setData({
        orderList: orderList,
        total: result.data.total
      })
    }
  }
})
